package com.itcast.service.impl;

import com.itcast.dao.GoodDao;
import com.itcast.domain.Good;
import com.itcast.service.GoodService;
import com.itcast.utils.ResponseBodyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("goodService")
public class GoodServiceImpl implements GoodService {

    @Autowired
    private GoodDao goodDao;

    @Override
    public List<Good> findAll() {
        return goodDao.findAll();
    }

    @Override
    public int saveGood(Good good) {
        return goodDao.saveGood(good);
    }

    @Override
    public Good findByName(String name) {
        return goodDao.findByName(name);
    }

    @Override
    public Good findById(String id) {
        return goodDao.findById(id);
    }

    @Override
    public int update(Good good) {
        return goodDao.update(good);
    }

    @Override
    public int delete(String id) {
        return goodDao.delete(id);
    }

    @Override
    public List<Good> findByNameLike(String name) {
        return goodDao.findByNameLike(name);
    }

    /**
     * 批量上线
     * @param list
     * @return
     * @throws Exception
     */
    @Override
    public String isOnline(List<String> list) throws Exception {
        int count = goodDao.isOnline(list);
        if (count > 0){
            return ResponseBodyUtil.getSuccessNoObject("修改");
        } else {
            return ResponseBodyUtil.getUnSuccessNoObject("修改");
        }
    }

    /**
     * 批量下线
     * @param list
     * @return
     * @throws Exception
     */
    @Override
    public String offLine(List<String> list) throws Exception {
        int count = goodDao.offLine(list);
        if (count > 0){
            return ResponseBodyUtil.getSuccessNoObject("修改");
        } else {
            return ResponseBodyUtil.getUnSuccessNoObject("修改");
        }
    }

    /**
     * 批量删除
     * @param list
     * @return
     */
    @Override
    public String batchDelete(List<String> list) throws Exception {
        int count = goodDao.batchDelete(list);
        if (count > 0){
            return ResponseBodyUtil.getSuccessNoObject("删除");
        } else {
            return ResponseBodyUtil.getUnSuccessNoObject("删除");
        }
    }
}
